[API-95] Add resolve endpoint, improve permalink matching#55
[API-95] Add resolve endpoint, improve permalink matching#55raymondjacobson merged 3 commits intomainfrom
Conversation
| splits := strings.Split(permalinks[i], "/") | ||
| if len(splits) != 2 { | ||
| if match := trackURLRegex.FindStringSubmatch(permalink); match != nil { | ||
| handles[i] = strings.ToLower(match[1]) |
There was a problem hiding this comment.
Smart, though iirc the query also does toLower - probably good to be defensive
There was a problem hiding this comment.
the query doesn't, ill update it to though
stereosteve
left a comment
There was a problem hiding this comment.
Looks good. Few notes.
| SELECT user_id FROM users | ||
| WHERE | ||
| handle_lc = lower(@handle) | ||
| AND is_current = true |
There was a problem hiding this comment.
why do we still is_current?
| err := app.pool.QueryRow(context.Background(), sql, handle).Scan(&userId) | ||
| app.resolveHandleCache.Set(handle, userId) | ||
| return userId, err | ||
| user_id, err := app.queries.GetUserForHandle(context.Background(), handle) |
There was a problem hiding this comment.
we should actually if err != nil {return err} here. My bad on that.
This should return pgx.ErrNoRows if not found I believe.
So returning on error avoids setting no_exist_handle = 0 in the cache... which would be bad if the indexer is behind and it might work on next try.
There was a problem hiding this comment.
yeah great catch
| return fiber.NewError(fiber.StatusBadRequest, "Missing handle parameter") | ||
| } | ||
|
|
||
| userId, err := app.queries.GetUserForHandle(c.Context(), handle) |
There was a problem hiding this comment.
we could app. resolveUserHandleToId here to use cache.
There was a problem hiding this comment.
this file isnt' even needed. oops
New working URLs
http://localhost:1323/v1/resolve?url=https://audius.co/jacknifemusic/jacknife-bladeboi-on-my-mind-remix-contest
http://localhost:1323/v1/resolve?url=https://audius.co/sturmfrau/playlist/this-is-sturmfrau
http://localhost:1323/v1/resolve?url=https://audius.co/oshimakesmusic
Tested=